package com.example.springboot01.conditional;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @author keyer
 * @Description : 符合哪种条件，就注入哪种service
 * Created by cyd on 2021-05-06 09:39:36
 */
@Configuration
public class ConditionConfig {
    /**
     * 如果WindowsCondition中matches方法判断得到true，则注入WindowsListService类的bean
     *
     * @return 向容器中注入bean
     */
    @Bean
    @Conditional(WindowsCondition.class)
    public ListService windowsListService() {
        return new WindowsListServiceImpl();
    }

    /**
     * 如果LinuxCondition中matches方法判断得到true，则注入LinuxCondition类的bean
     *
     * @return 向容器中注入bean
     */
    @Bean
    @Conditional(LinuxCondition.class)
    public ListService linuxListService() {
        return new LinuxListServiceImpl();
    }
}
